/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package me.zhy.swing;

import java.awt.Component;
import java.awt.Container;

/**
 *
 * @author Moon
 */
public class AWTUtilities {

    public static void removeChildrenNotify(Container container) {
        synchronized (container.getTreeLock()) {
            int count = container.getComponentCount();
            for (int i = 0; i < count; i++) {
                container.getComponent(i).removeNotify();
            }
        }
    }

    public static void addChildrenNotify(Container container) {
        synchronized (container.getTreeLock()) {
            int count = container.getComponentCount();
            for (int i = 0; i < count; i++) {
                container.getComponent(i).addNotify();
            }
        }
    }

    public static void remove(Component comp) {
        Container parent = comp.getParent();
        if (parent == null) {
            return;
        }
        parent.remove(comp);
        parent.repaint(comp.getX(), comp.getY(), comp.getWidth(), comp.getHeight());
    }
}
